<?php 
require_once('Class/language.Class.php');

/**
	Class used to display correctly the html data from a php var
*/
Class displayInHtml
{
	var $maxNumberCriteria = 0;

	function getMaxNumberCriteria()
	{
		return $this->maxNumberCriteria;
	}

	/**
		Return the html display of a select
	*/
	static function getSelectListFromArray($data)
	{
		$display = '';

		foreach ($data as $row)
		{
			$display .= '<option value="'. $row['name'] .'">' . $row['name'] . '</option>';
		}
		return $display;
	}

	/**
		Return the html display of a list of checkbox
	*/
	static function getCheckboxListFromArray($data)
	{
		$display = '';
		$i = 0;

		foreach ($data as $row)
		{
			$display .= "<div class='col-sm-4'>
							<label>
								<input name='group". $row['id'] ."' type='checkbox' value='". $row['name'] ."'>
							</label>
							<label>". 
								$row['name'] 
							."</label>
						</div>";
			$i++;
		}
		return $display;
	}

	/**
		Return the html display of a list of checkbox
	*/
	static function getCheckedListFromArray($groups, $groupsChecked)
	{
		$display = '';
		$i = 0;
		$groupsChecked = explode(';', $groupsChecked);
		foreach ($groups as $row)
		{
			if (in_array($row['id'], $groupsChecked))
			{
				$checked = " checked ";
			}
			else
			{
				$checked = "";
			}
			$display .= "<div class='col-sm-4'>
							<label>
								<input name='group". $row['id'] ."' type='checkbox' value='". $row['id'] ."' ". $checked .">
							</label>
							<label>". 
								$row['name'] 
							."</label>
						</div>";
			$i++;
		}
		return $display;
	}

	/**
		Return the html display of a select for the account type
		Can be given the option we want to be selected
	*/
	static function getRadioListFromArray($name, $selected)
	{
		$accountType = array('1' => 'Admin', '2' => 'Manager');
		$display = '';
		foreach ($accountType as $key => $value)
		{
			if ($key == $selected)	
			{
				$displayChecked = " checked='checked' ";
			}
			else
			{
				$displayChecked = '';
			}
			$display .= "<input type='radio' name='". $name ."' value='".$key."' ". $displayChecked ."> ". $value ."<br>"; 
		}
		return $display;
	}

	/**
		Return header of the tab (used in create_new_rating.php)
	*/
	function getLevelRatingTab($get)
	{
		$html = '';
		$criteriaMark = array();
		
		foreach ($get as $key => $value)
		{
			if (strpos($key, 'nameCriteria') !== false && $value != '')
			{
				$exploded  = explode('_', $key);
				$idx = $exploded[1];
				$criteriaMark [strtolower($value)] = $get['markCriteria2_' . $idx];
			}
		}
		$this->maxNumberCriteria = count($criteriaMark);
		foreach ($criteriaMark as $key => $value)
		{
			if ($value != '')
			{
				$html .= '<th>' . ucfirst($key) . ' (' . $value .') ' . '</th>';
			}
		}
		return $html;
	}

	function getTabContent($get)
	{
		//var_dump($get);
		$html = '<tr>';
		foreach ($get as $key => $value)
		{
			if (strpos($key, 'titleCriteria') !== false)
			{
				$html .= '<td class="bg-purple">' . $value . '</td>';
			}
			if (strpos($key, 'descriptionCriteria') !== false)
			{
				$html .= '<td>' . $value . '</td>';
			}
			if (strpos($key, 'coeffCriteria') !== false)
			{
				$html .= '<td class="bg-light-blue">' . $value . '</td>';
			}
			if (strpos($key, 'endCriteria') !== false)
			{
				for ($i=0; $i < $this->maxNumberCriteria; $i++)
				{ 
					$html .= "<td><input type='radio' name='test'></td>";
				}
				$html .= "<td><textarea class='form-control' rows='3'></textarea></td>";
				$html .= '</tr><tr>';
			}
		}

		$html .= '</tr>';
		return $html;
	}
}
?>